package edu.faytechcc.csc.gui;

import edu.faytechcc.csc.messages.Connection;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/**
 * Please describe what this class does here.
 *
 * CSC 251 0001 DATE:
 *
 * @author Stephanie Mckenzie
 */
public class TextPanel extends JPanel
{

    private Connection conn;
    private JTextArea messagesArea;
    private JTextField messageTextField; //to enter a message to send
    private JButton sendButton;

    public TextPanel(String name)
    {
        UserInformationPanel userInfoPanel = new UserInformationPanel(name);

        this.setLayout(new BorderLayout(10, 10));
        this.add(userInfoPanel);
        this.add(messagesArea);
        this.add(messageTextField);
        this.add(sendButton);
    }

    public void addMessage(String message)
    {
        messagesArea.append(message + "/n");
        messagesArea.setCaretPosition(messagesArea.getDocument().getLength());
    }

    class TextFieldActionListener implements ActionListener
    {

        @Override
        public void actionPerformed(ActionEvent e)
        {
            String msg = messageTextField.getText();
            conn.sendMessages(msg);

            messagesArea.append(msg + "/n");
            messageTextField.setText("");
            messagesArea.setCaretPosition(messagesArea.getDocument().getLength());
        }
    }
}
